package com.qipay.baas.mapper;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.VALUES;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.qipay.baas.model.SpApiConfig;

public class SpApiConfigSqlProvider {

    public String insertSelective(SpApiConfig record) {
        BEGIN();
        INSERT_INTO("sp_api_config");
        
        if (record.getId() != null) {
            VALUES("id", "#{id,jdbcType=BIGINT}");
        }
        
        if (record.getSpId() != null) {
            VALUES("sp_id", "#{spId,jdbcType=BIGINT}");
        }
        
        if (record.getChannelType() != null) {
            VALUES("channel_type", "#{channelType,jdbcType=TINYINT}");
        }
        
        if (record.getApiType() != null) {
            VALUES("api_type", "#{apiType,jdbcType=INTEGER}");
        }
        
        if (record.getKey() != null) {
            VALUES("`key`", "#{key,jdbcType=VARCHAR}");
        }
        
        if (record.getVal() != null) {
            VALUES("val", "#{val,jdbcType=VARCHAR}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(SpApiConfig record) {
        BEGIN();
        UPDATE("sp_api_config");
        
        if (record.getSpId() != null) {
            SET("sp_id = #{spId,jdbcType=BIGINT}");
        }
        
        if (record.getChannelType() != null) {
            SET("channel_type = #{channelType,jdbcType=TINYINT}");
        }
        
        if (record.getApiType() != null) {
            SET("api_type = #{apiType,jdbcType=INTEGER}");
        }
        
        if (record.getKey() != null) {
            SET("`key` = #{key,jdbcType=VARCHAR}");
        }
        
        if (record.getVal() != null) {
            SET("val = #{val,jdbcType=VARCHAR}");
        }
        
        WHERE("id = #{id,jdbcType=BIGINT}");
        
        return SQL();
    }
}